#ifndef MUTEX_H
#define MUTEX_H

#include <pthread.h>

class Mutex {
private:
	pthread_mutex_t m;
	pthread_cond_t cv;
	Mutex(const Mutex &c);
public:
	Mutex();
	~Mutex();
	void lock();
	void unlock();
	void wait();
	void signal();
	void broadcast();
	friend class Lock;
};

class Lock {
private:
	Mutex &m;
	Lock(const Lock &c) :
			m(c.m) {
	}
	;
public:
	Lock(Mutex &m) :
			m(m) {
		m.lock();
	}
	~Lock() {
		m.unlock();
	}
	void wait() {
		m.wait();
	}
	void signal() {
		m.signal();
	}
	void broadcast() {
		m.broadcast();
	}
};
#endif

